<?php
//@app_header;


include_once 'core/cjax_config.php';
$ajax = CJAX::getInstance();

/**
 * Handle mod_rewrite redirect
 */
if(isset($_SERVER['REDIRECT_QUERY_STRING']) && $_SERVER['REDIRECT_QUERY_STRING']) {
	$_SERVER['QUERY_STRING'] = $_SERVER['REDIRECT_QUERY_STRING'];
}
/**
 * Handle friendly URLS
 */
if(isset($_SERVER['QUERY_STRING']) && $query = $_SERVER['QUERY_STRING']) {
	$packet = explode('/' ,$query);
	
	if($packet && count(array_keys($packet)) >= 2 && $packet[0] && $packet[1]) {
		$_REQUEST['controller'] = $packet[0];
		$_REQUEST['function'] = $packet[1];
		$_REQUEST['cjax'] = time();
		unset($packet[0]);
		unset($packet[1]);
		if($packet){
			$params = array('a','b','c','d','e','f');
			do {
				$_REQUEST[current($params)] = current($packet);
			} while(next($packet) && next($params));
		}
		define('CJAX_RESPONSE', 1);
	}
}

if(!$ajax->isAjaxRequest()) {
	if(count(array_keys(debug_backtrace(false))) == 1) {
		exit("Security Error. You cannot access this file directly.");
	}
}